import { createRouter, createWebHashHistory } from 'vue-router';
const Home = () => import('../views/home/index.vue');
const Categroy = () => import('../views/category');
const Detail = () => import('../views/detail');
const Profile = () => import('../views/profile');
const ShopCart = () => import('../views/shopcart');


const routes = [
  {
    path: '',
    name: 'DefaultHome',
    component: Home,
    meta: {
      title:'图书兄弟'
    }

  },
  {
    path: '/home',
    name: 'Home',
    component: Home,
    meta: {
      title:'图书兄弟'
    }
  },
  {
    path: '/category',
    name: 'Category',
    component: Categroy,
    meta: {
      title:'图书兄弟-商品分类'
    }
  },
  {
    path: '/detail',
    name: 'Detail',
    component: Detail,
    meta: {
      title:'图书兄弟-商品详情'
    }
  },
  {
    path: '/shopcart',
    name: 'ShopCart',
    component: ShopCart,
    meta: {
      title:'图书兄弟-购物车',
      isAuthRequired:true
    }
  },
  {
    path: '/profile',
    name: 'Profile',
    component: Profile,
    meta: {
      title:'图书兄弟-个人中心',
      isAuthRequired:true
    }
  }
]

const router = createRouter({
  history: createWebHashHistory(),
  routes
})


// 路由守卫
router.beforeEach((to, from, next)=>{
  // 如果没有登录， 在这里到login
  // if(to.meta.isAuthRequired && store.state.user.isLogin === false) {
  //   Notify('您还没有登录， 请先登录');
  //   return next('/login');
  // }else{
  //   next();
  // }

  next();
  document.title = to.meta.title;
})

export default router
